<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>搜索</title>
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"
    />
    <link href="../../../../css/mui.min.css" rel="stylesheet" />
    <link href="../../css/common.css" rel="stylesheet" />
    <link href="../../css/helper.css" rel="stylesheet" />
    <style>
      .mui-table-view-cell {
        padding: 0 0;
      }

      .list-item {
        height: 67px;
        border-radius: 3px;
        margin-bottom: 13px;
        background-color: #ffffff;
        padding-left: 16px;
        padding-right: 13px;
      }

      .card-img-box {
        /* margin-right:16px; */
        height: inherit;
        width: 33px;
      }

      .card-img {
        width: 33px;
        height: 33px;
      }

      .card-content-box {
        padding: 0 16px;
        width: 76%;
      }

      .txt1 {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #333333;
        text-overflow: ellipsis;
        overflow: hidden;
      }

      .txt2 {
        font-size: 13px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #999999;
      }

      .img-tool-box {
        /* height:inherit; */
        width: 44px;
        /* flex: 1; */
      }
      .img-tool-box .imgs {
        display: inline-block;
        width: 20px;
        height: 20px;
      }
      .img-tool {
        width: 19px;
        height: 19px;
        /* margin-top:10px; */
      }

      .img-19 {
        width: 19px;
        height: 19px;
      }

      .mui-table-view {
        margin-top: 44px;
        background-color: inherit;
        padding-left: 13px;
        padding-right: 13px;
        padding-top: 13px;
      }

      .mui-table-view-cell:after {
        background-color: #ffffff;
        margin-bottom: 13px;
      }
      .searchs {
        display: flex;
        justify-content: space-between;
      }
      .selects {
        display: flex;
      }
      .search-picker {
        width: 90px;
        border: solid 1px #ccc !important;
        height: 30px;
      }
      .btns .mui-btn {
        height: 30px;
        margin-left: 10px;
      }
    </style>
  </head>

  <body>
    <div id="container" v-cloak>
      <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">搜索</h1>
        <!-- <div class="img-tool-boxs">
          <img src="../../img/sousuo.png" class="img-tool fr" style="margin-left:13px;margin-top: 10px;" @click="search">
        </div> -->
      </header>
      <div class="mui-content">
        <!-- 1、slider items -->
        <div
          class="mui-bar mui-segmented-control mui-segmented-control-inverted mui-segmented-control-primary"
        >
          <div class="searchs">
            <div class="selects">
              <select
                style="width: 90px"
                v-model="selectval"
                class="mui-btn mui-btn-block search-picker"
                placeholder="请选择"
              >
                <option
                  v-for="item in selectList"
                  :key="item.id"
                  :value="item.id"
                >
                  {{item.name}}
                </option>
                <!-- <option value="2">上传人</option>
              <option value="3">编码</option>
              <option value="4">厂商型号</option> -->
              </select>
              <div class="mui-input-row mui-search">
                <input
                  type="search"
                  v-model="searchVal"
                  class="mui-input-clear"
                  placeholder=""
                />
              </div>
            </div>
            <div class="btns">
              <button
                type="button"
                @tap="searchInput()"
                class="mui-btn mui-btn-primary"
              >
                搜索
              </button>
            </div>

            <!-- <input  class="search-input fs" v-model="searchVal" placeholder="请输入用户名"> -->
          </div>

          <!-- <a class="mui-control-item" v-for="(v,i) in typeList" :key="v.id" :class="i==0?'mui-active':''" href="#item0" @tap="getSystemList(v.id)">{{v.n}}</a> -->
          <!-- <a class="mui-control-item" href="#item2">验收制度</a>
					<a class="mui-control-item" href="#item3">监管制度</a> -->
        </div>
        <div id="slider" class="mui-slider mui-fullscreen">
          <div class="tab-content mui-slider-group" id="tab-content">
            <div
              id="item0"
              class="mui-slider-item mui-control-content mui-active"
            >
              <div id="scroll" class="regular-scroll mui-scroll-wrapper">
                <div class="mui-scroll">
                  <!-- 2、列表 -->
                  <ul class="mui-table-view">
                    <li
                      class="mui-table-view-cell mui-media list-item f-r-b-c"
                      v-for="(item,index) in systemList"
                      :key="item.id"
                      @tap="detail(item.id)"
                    >
                      <div class="card-img-box f-r-c-c">
                        <img src="../../img/wenjian.png" class="card-img" />
                      </div>
                      <div class="card-content-box fs">
                        <div v-if="type==1">
                          <div class="txt1">{{item.fn}}</div>
                          <div class="txt2">{{item.c}}</div>
                        </div>
                        <div v-else-if="type==2">
                          <div class="txt1">{{item.dm}} - {{item.t}}</div>
                          <div class="txt2">{{item.fn}}</div>
                        </div>
                        <div v-else-if="type==3">
                          <div class="txt1">{{item.t}}</div>
                          <div class="txt2">{{item.cn}}</div>
                        </div>
                        <div v-else-if="type==4">
                          <div class="txt2">{{item.fan}} - {{item.mon}}</div>
                          <div class="txt1">{{item.fn}}</div>
                          <div class="txt2">{{item.cn}}</div>
                        </div>
                      </div>
                      <!--<div class="img-tool-box">
                        <div class="texts" v-if="type==2||type==4">
                          <span>{{item.cn}}</span>
                        </div>
                        <span class="imgs" @tap.stop="downlonds(item)"
                          ><img src="../../img/xiazai.png" class="img-tool fr"
                        /></span>
                        <span class="imgs" v-if="item.ic"
                          ><img
                            src="../../img/shoucang_yishoucang.png"
                            class="img-tool fr"
                        /></span>
                        <span class="imgs" v-else
                          ><img
                            src="../../img/shoucang_moren.png"
                            class="img-tool fr"
                        /></span>
                      </div>-->
                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script src="../../../../js/mui.js"></script>
    <script src="../../../../js/mui.pullToRefresh.js"></script>
    <script src="../../../../js/mui.pullToRefresh.material.js"></script>
    <!-- <script src="../../../../js/jquery-1.7.2.min.js"></script> -->
    <script
      type="text/javascript"
      src="../../../../js/jquery-3.2.1.min.js"
    ></script>
    <script src="../../../../js/vue.js"></script>
    <script src="../../js/mkeyplus.base.js"></script>
    <script src="../../js/sqlite.js"></script>
    <script type="text/javascript">
      mui.init()
      let type = 1
      if (window.plus) {
        plusready()
      } else {
        document.addEventListener("plusready", plusready, false)
      }
      function plusready() {
        var self = plus.webview.currentWebview()
        console.log("122d", self)
        type = self.type
        vm.type = self.type
        // vm.getDetils()
        mui.DB.openSqlite()
        // 标准规范库
      }
      let vm = new Vue({
        el: "#container",
        data: {
          ids: "",
          selectval: "1",
          searchVal: "",
          form: {
            page: 1,
            size: 20,
            donePage: 1,
            system: "APP",
            status: 1,
          },
          selectList: [
            {
              name: "文件名",
              id: 1,
            },
            {
              name: "上传人",
              id: 2,
            },
          ],
          systemList: [],
          typeList: [],
          downList: [],
          downType: [],
          details: {},
        },
        watch: {
          searchVal: {
            handler(val) {
              this.getdata(val)
            },
          },
        },
        created: function () {
          // this.getSystemList()
          // this.getType()
        },
        methods: {
          searchInput() {
            this.getdata(this.searchVal)
          },
          getdata(val) {
            // let selKey= this.selectval=='1'?'fileName':this.selectval=='2'?'createName':this.selectval=='3'?'classifyCode':this.selectval=='4'?'machineModel':'fileName'

            // 标准规范库
            if (type == "1") {
              let selKey =
                this.selectval == "1"
                  ? "fileName"
                  : this.selectval == "2"
                  ? "createName"
                  : "fileName"
              this.selectList = [
                {
                  name: "文件名",
                  id: 1,
                },
                {
                  name: "上传人",
                  id: 2,
                },
              ]
              let tech = [
                {
                  key: selKey,
                  value: val,
                  has: true
                },
              ]
              console.log("表21规范", tech)
              mui.DB.selectTableData("dataStand", tech)
                .then((res) => {
                  console.log("表21", res)
                  this.systemList = val ?res : []
                })
                .catch((error) => {
                  console.log(error)
                })
            } else if (type == "2") {
              //设备资料库
              let selKey =
                this.selectval == "1"
                  ? "title"
                  : this.selectval == "2"
                  ? "createName"
                  : "title"
              this.selectList = [
                {
                  name: "文件名",
                  id: 1,
                },
                {
                  name: "上传人",
                  id: 2,
                },
              ]
              let tech = [
                {
                  key: selKey,
                  value: val,
                  has: true
                },
              ]
              mui.DB.selectTableData("dataDevice", tech)
                .then((res) => {
                  console.log("表2", res)
                  this.systemList = val ?res : []
                })
                .catch((error) => {
                  console.log(error)
                })
            } else if (type == "3") {
              //技术交流
              let selKey =
                this.selectval == "1"
                  ? "title"
                  : this.selectval == "2"
                  ? "createName"
                  : this.selectval == "3"
                  ? "classifyCode"
                  : this.selectval == "4"
                  ? "machineModel"
                  : "title"
              this.selectList = [
                {
                  name: "文件名",
                  id: 1,
                },
                {
                  name: "上传人",
                  id: 2,
                },
                {
                  name: "编码",
                  id: 3,
                },
                {
                  name: "厂商型号",
                  id: 4,
                },
              ]
              console.log("技术交流11")
              let tech = [
                {
                  key: selKey,
                  value: val,
                  has: true
                },
              ]
              console.log("技术交流", tech)
              mui.DB.selectTableData("technology", tech)
                .then((res) => {
                  console.log("表2", res)
                  this.systemList = val ?res : []
                })
                .catch((error) => {
                  console.log(error)
                })
            } else if (type == 4) {
              //故障案例集
              let selKey =
                this.selectval == "1"
                  ? "faultName"
                  : this.selectval == "2"
                  ? "faultCode"
                  : this.selectval == "3"
                  ? "classifyCode"
                  : this.selectval == "4"
                  ? "machineModel"
                  : "title"
              this.selectList = [
                {
                  name: "故障名",
                  id: 1,
                },
                {
                  name: "故障号",
                  id: 2,
                },
                {
                  name: "编码",
                  id: 3,
                },
                {
                  name: "厂商型号",
                  id: 4,
                },
              ]
              let tech = [
                {
                  key: selKey,
                  value: val,
                  has: true
                },
              ]
              mui.DB.selectTableData("dataFaults", tech)
                .then((res) => {
                  console.log("表2", res)
                  this.systemList = val ?res : []
                })
                .catch((error) => {
                  console.log(error)
                })
            }
          },
          getSystemList(id) {
            this.ids = id
            if (this.form.page === 1) {
              // plus.nativeUI.showWaiting('加载中...');
            }
            mui.baseApp.httpRequst(
              "get",
              "/app/api/knowledge/standard",
              {
                page: this.form.page,
                size: this.form.size,
                classifyCode: id,
              },
              (data) => {
                console.log("www", data)
                // plus.nativeUI.closeWaiting();
                if (this.form.page == 1) {
                  this.systemList = []
                }
                this.systemList = this.systemList.concat(data.records)
                if (data.records.length < this.form.size) {
                  //
                  mui("#item0 .mui-scroll")
                    .pullToRefresh()
                    .endPullUpToRefresh(true) //参数为true代表没有更多数据了。
                  return
                } else {
                  mui("#item0 .mui-scroll")
                    .pullToRefresh()
                    .endPullUpToRefresh(false) //参数为true代表没有更多数据了。
                  mui("#item0 .mui-scroll").pullToRefresh().refresh(true) //启用上拉加载
                }
              },
              function () {
                // plus.nativeUI.closeWaiting()
                console.log("获取数据失败")
              }
            )
          },
          getType() {
            mui.baseApp.httpRequst(
              "get",
              "/app/api/knowledge/standard/type",
              {},
              (data) => {
                console.log("dd", data)
                this.typeList = data
                this.ids = data[0].id
                this.getSystemList(this.ids)
                this.typeList.forEach((res) => {
                  mui.DB.createFormat("typeStand", res, "id")
                  mui.DB.insertOrReplace("typeStand", res)
                })
              },
              function () {
                // plus.nativeUI.closeWaiting()
                console.log("获取数据失败")
              }
            )
          },
          downlonds(item) {
            console.log("123", item)
            this.getDetils(item)
          },
          setObj(arr) {
            console.log("arr", arr)
            let newArr = []
            let obj = {}
            for (var i = 0; i < arr.length; i++) {
              if (!obj[arr[i].id]) {
                newArr.push(arr[i])
                obj[arr[i].id] = true
              }
            }
            return newArr
          },
          getDetils(item) {
            let than = this
            let idss = item.id

            mui.baseApp.httpRequst(
              "get",
              "/app/api/knowledge/standard/detail/" + idss,
              {},
              function (data) {
                console.log("120", data.data)
                let itms = data.data
                // than.details=itms
                let detas = {
                  id: itms.id,
                  knowledgeType: itms.knowledgeType || "",
                  classifyCode: itms.classifyCode || "",
                  fileId: itms.fileId || "",
                  fileName: itms.fileName || "",
                  fileUrl: itms.fileUrl || "",
                  createId: itms.createId || "",
                  createTime: itms.createTime || "",
                  updateId: itms.updateId || "",
                  updateTime: itms.updateTime || "",
                  deleted: itms.deleted || "",
                  createName: itms.createName || "",
                  knowledgeTypeName: itms.knowledgeTypeName || "",
                  classifyCodeName: itms.classifyCodeName || "",
                }
                // let itm= $.extend(than.details,item)
                mui.DB.createFormat("dataStand", detas, "id")
                mui.DB.insertOrReplace("dataStand", detas)
              },
              function () {
                // plus.nativeUI.closeWaiting()
                console.log("获取数据失败1")
              }
            )
          },
          detail(id) {
            mui.baseApp.openWindow("./detail.html", {
              ids: id,
            })
          },
          search() {
            mui.baseApp.openWindow("../../common/search.html", {
              typeid: 1,
            })
          },
        },
      })

      ;(function ($) {
        //阻尼系数
        var deceleration = mui.os.ios ? 0.003 : 0.0009
        $(".mui-scroll-wrapper").scroll({
          bounce: false,
          indicators: true, //是否显示滚动条
          deceleration: deceleration,
        })
        $.ready(function () {
          $(".mui-scroll").pullToRefresh({
            down: {
              callback: function () {
                var self = this
                setTimeout(function () {
                  vm.form.page = 1
                  vm.getSystemList(vm.ids)
                  self.endPullDownToRefresh()
                }, 1000)
              },
            },
            up: {
              callback: function () {
                var self = this
                setTimeout(function () {
                  mui.toast("11111")
                  console.log(index)
                  vm.form.page++
                  vm.getSystemList(vm.ids)
                  self.endPullUpToRefresh()
                }, 1000)
              },
            },
          })

          mui("#item0 .mui-scroll").pullToRefresh().endPullUpToRefresh(true)
          // mui("#item2 .mui-scroll").pullToRefresh().endPullUpToRefresh(true);
        })
      })(mui)
    </script>
  </body>
</html>
